//
//  PpBarometerVC.swift
//  Palmpilot
//
//  Created by 杨伟毅 on 2018/10/22.
//  Copyright © 2018年 杨伟毅. All rights reserved.
//

import UIKit
import CoreMotion
import QorumLogs
class PpBarometerVC: PpBaseViewController {
    lazy var altimer = CMAltimeter()
    
    @IBOutlet weak var baseLabel: UILabel!
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.title = PpLanguageSwitchTool.getString(key: "barometer")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        if CMAltimeter.isRelativeAltitudeAvailable() {
            
            altimer.startRelativeAltitudeUpdates(to:OperationQueue.main) { (altitudeData, error) in
                if error == nil{
                    self.baseLabel.text =  PpLanguageSwitchTool.getString(key: "The current air pressure") + String.init(format:"%.4f", (altitudeData?.pressure.floatValue)!) + "kPa"
                }else{
                    QL1("打印错误状态\(error!)")
                }
            }
        }
        
        // Do any additional setup after loading the view.
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    deinit {
        altimer.stopRelativeAltitudeUpdates()
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
